package com.dc.project_java.test.lazy;

import androidx.lifecycle.MutableLiveData;

import com.dc.base.network.RequestCallback;
import com.dc.base.viewmodel.BaseViewModel;

import io.reactivex.disposables.Disposable;

public class LazyViewModel extends BaseViewModel {

    private MutableLiveData<JueJinBean> jueJinLiveData = new MutableLiveData<>();

    private LazyRepository repository = new LazyRepository();

    public void loadData(String category) {
        loadingDialogLiveData.setValue(true, "懒加载中");
        Disposable disposable = repository.getJueJin(category, new RequestCallback<JueJinBean>() {
            @Override
            public void onSuccess(JueJinBean jueJinBean) {
                loadingDialogLiveData.setValue(false);
                jueJinLiveData.setValue(jueJinBean);
            }

            @Override
            public void onFailure(int code, String errorMsg) {
                loadingDialogLiveData.setValue(false);
            }
        });
        addDisposable(disposable);
    }

    public MutableLiveData<JueJinBean> getJueJinLiveData() {
        return jueJinLiveData;
    }
}
